package com.lunatic.controller;

import com.lunatic.entity.Company;
import com.lunatic.service.CompanyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Random;
import java.util.UUID;

/**
 * the class of springcloud
 *
 * <p>
 * .
 *
 * @author little_lunatic
 * @date 2024-05-22
 */
@RestController
@RequestMapping("/company")
@Slf4j
public class CompanyController {

    @Resource
    private CompanyService companyService;

//    @Resource
//    private IdService idService;

    @GetMapping("/add")
    public Boolean add() {
        Company company = new Company();
        company.setId((long) new Random().nextInt(10000));
        company.setName("企业名称；" + UUID.randomUUID());
        company.setCreateTime(LocalDateTime.now());
        company.setUpdateTime(LocalDateTime.now());
        log.info("add {}", company);
        return companyService.save(company);
    }

    @GetMapping("/get/{id}")
    public Company get(@PathVariable(name = "id") int id) {
        Company company = companyService.find(id);
        log.info("get {}", company);
        return company;
    }
}
